﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ChoJu.Single.Views
{
    /// <summary>
    /// ViewRatingMsg.xaml 的交互逻辑
    /// </summary>
    public partial class ViewRatingMsg : UserControl
    {
        private Timer _timer;
        private DateTime _dateTime;

        public ViewRatingMsg()
        {
            InitializeComponent();

            _timer = new Timer(1000 * 1);
            _timer.Elapsed += _timer_Elapsed;
            //_timer.Start();

            Visibility = Visibility.Collapsed;
        }

        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if ((DateTime.Now - _dateTime).TotalSeconds < 10)
                return;

            //_timer.Stop();
            Dispatcher.Invoke(() => Visibility = Visibility.Collapsed);
        }

        public void View(string levName, int rating)
        {
            _dateTime = DateTime.Now;
            Visibility = Visibility.Visible;

            if (_timer.Enabled == false)
                _timer.Start();

            if(levName.ToLower().StartsWith("cx") == true)
            {
                tbkMsg.Text = "杂烟";
                tbkMsg.Foreground = Brushes.Red;
            }
            else if(levName.ToLower().StartsWith("gy") == true)
            {
                tbkMsg.Text = "青烟";
                tbkMsg.Foreground = Brushes.LightGreen;
            }
            else
            {
                tbkMsg.Text = $"{rating}类";
                tbkMsg.Foreground= Brushes.Orange;
            }
        }

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            //_timer.Stop();
            this.Visibility = Visibility.Collapsed;
        }
    }
}
